<!--
 * @Date: 2021-03-01 21:32:55
 * @名称: app 设置 - app列表
 * @版本: 0.01
 * @作者: 初雪桜
 * @邮箱: 202184199@qq.com
 * @最后编辑: 初雪桜
 * @LastEditTime: 2021-03-11 20:54:32
 * @FilePath: /Site/app/useradmin/view/app/AppList/AppList.html
-->
<html>

<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
    <title>网站后台管理模版</title>
    <link rel="stylesheet" type="text/css" href="/static/admin/layui/css/layui.css">
    <link rel="stylesheet" type="text/css" href="/static/admin/css/admin.css">
    <script src="/public/static/admin/imgupdate/jquery.min.js"></script>
    <script src="/public/static/tisp.js"></script>
    <script src="/public/static/other.js"></script>
    <style>
        td {
            text-align: center;
        }

        body .layer-test {
            background: none;
            box-shadow: none;
        }
    </style>
</head>

<body>
    <div class="page-content-wrap">
        <form class="layui-form" id="screen-where">
            <div class="layui-form-item">

                强制更新
                <div class="layui-inline">

                    <select id="uorce_update" lay-filter="status">
                        <option value="2">任意</option>
                        <option value="0">否</option>
                        <option value="1">是</option>
                    </select>
                </div>
                是否禁用
                <div class="layui-inline">

                    <select id="disable" lay-filter="status">
                        <option value="2">任意</option>
                        <option value="0">否</option>
                        <option value="1">是</option>
                    </select>

                </div>
                每页显示
                <div class="layui-inline">
                    <input id="onePageData" placeholder="" value="15" autocomplete="off" class="layui-input">
                </div>
                <button type="button" class="layui-btn layui-btn-normal button-screen">筛选</button>
                <div style="float:right " class="layui-inline tool-btn">
                    <button class="layui-btn layui-btn-small layui-btn-normal go-btn hidden-xs"
                        data-url="/{$useradmin}/App/AppSetting/EditAppList"><i class="layui-icon"></i></button>
                </div>
            </div>
        </form>
        <div class="layui-form">
            <table class="layui-table" lay-even="" lay-skin="nob">
                <colgroup>
                    <col class="hidden-xs" width="5">
                    <col width="100">
                    <col>
                    <col class="hidden-xs" width="100">
                    <col width="100">
                    <col width="100">
                    <col width="100">
                </colgroup>
                <thead>
                    <tr>
                        <th style="text-align: center;" class="hidden-xs">ID</th>
                        <th style="text-align: center;">类型</th>
                        <th style="text-align: center;">发布时间</th>
                        <th style="text-align: center;">版本</th>
                        <th style="text-align: center;">编译版本</th>
                        <th style="text-align: center;">强制更新</th>
                        <th style="text-align: center;">强制更新的最低版本</th>
                        <th style="text-align: center;">下载地址</th>
                        <th style="text-align: center;">是否禁用</th>
                        <th style="text-align: center;">禁用原因</th>
                        <th style="text-align: center;">上传人</th>
                        <th style="text-align: center;">操作</th>
                    </tr>
                </thead>
                <tbody id="app_list">
                    {volist name='appList' id='appListValue'}
                    <tr data-id="{$appListValue.id}" data-version="{$appListValue.version}"
                        data-uuid_id="{$appListValue.uuid_id}">
                        <td class="hidden-xs">{$appListValue.id}</td>
                        {if $appListValue.platform == 0}
                        <td>IOS</td>
                        {else /}
                        <td>Android</td>
                        {/if}
                        <td>{$appListValue.upload_time}</td>
                        <td>{$appListValue.version}</td>
                        <td>{$appListValue.build_version}</td>
                        {if $appListValue.uorce_update == 1}
                        <td><button
                                class="layui-btn layui-btn-mini layui-btn-normal layui-btn-danger button-app-is_uorce_update"
                                data-status="1">是</button></td>
                        {else /}
                        <td><button class="layui-btn layui-btn-mini layui-btn-normal button-app-is_uorce_update"
                                data-status="0">否</button></td>
                        {/if}
                        <td>{$appListValue.minimum_version_number}</td>
                        <td>{$appListValue.download_url}</td>
                        {if $appListValue.disable == 1}
                        <td><button
                                class="layui-btn layui-btn-mini layui-btn-normal layui-btn-danger button-app-isdisable"
                                data-status="0">禁用</button></td>
                        {else /}
                        <td><button class="layui-btn layui-btn-mini layui-btn-normal button-app-isdisable"
                                data-status="1">正常</button></td>
                        {/if}
                        <td>{$appListValue.disable_info}</td>
                        <td>{$appListValue.user_name}</td>
                        <td>
                            <div class="layui-inline">
                                <button class="layui-btn layui-btn-mini layui-btn-normal  go-btn"><i
                                        class="layui-icon"></i></button>
                                <button class="layui-btn layui-btn-mini layui-btn-danger del-btn"><i
                                        class="layui-icon"></i></button>
                            </div>
                        </td>
                    </tr>
                    {/volist}
                </tbody>
            </table>
            <div id="paging">

            </div>


        </div>
    </div>
    <script src="/public/static/admin/layui/layui.js" type="text/javascript" charset="utf-8"></script>
    <script src="/public/static/admin/js/common.js" type="text/javascript" charset="utf-8"></script>

    <script>
        /**
         * @方法名:创建一条数据 
         * @作者: 初雪桜
         * @信息: 创建一条数据
         * @param {String} id 在数据库中的序号
         * @param {String} version 版本
         * @param {String} platform 类型
         * @param {String} upload_time 更新时间
         * @param {String} build_version 编译版本
         * @param {String} uorce_update 是否强制更新
         * @param {String} minimum_version_number 强制更新最低版本
         * @param {String} download_url 下载地址
         * @param {String} disable 是否禁用
         * @param {String} disable_info 禁用原因
         * @param {String} user_name 谁创建的
         * @return html
         */
        function listHtml(id, version, uuid_id, platform, upload_time, build_version, uorce_update, minimum_version_number, download_url, disable, disable_info, user_name) {
            $html =
                '<tr data-id="' + id + '" data-version="' + version + '" data-uuid_id="' + uuid_id + '">' +
                '<td class="hidden-xs">' + id + '</td>';
            if (platform == 0) {
                $html += '<td>IOS</td>';
            } else {
                $html += '<td>Android</td>';
            }
            $html += '<td>' + upload_time + '</td>' +
                '<td>' + version + '</td>' +
                '<td>' + build_version + '</td>';
            if (uorce_update == 1) {
                $html += '<td><button class="layui-btn layui-btn-mini layui-btn-normal layui-btn-danger button-app-is_uorce_update" data-status="1">是</button></td>';
            } else {
                $html += '<td><button class="layui-btn layui-btn-mini layui-btn-normal button-app-is_uorce_update" data-status="0">否</button></td>';
            }

            $html += '<td>' + minimum_version_number + '</td>' +
                '<td>' + download_url + '</td>';
            if (disable == 1) {
                $html += '<td><button class="layui-btn layui-btn-mini layui-btn-normal layui-btn-danger button-app-isdisable" data-status="0">禁用</button></td>';
            } else {
                $html += '<td><button class="layui-btn layui-btn-mini layui-btn-normal button-app-isdisable" data-status="1">正常</button></td>';
            }

            $html += '<td>' + disable_info + '</td>' +
                '<td>' + user_name + '</td>' +
                '<td>' +
                '<div class="layui-inline">' +
                '<button class="layui-btn layui-btn-mini layui-btn-normal  go-btn"><i class="layui-icon"></i></button>' +
                '<button class="layui-btn layui-btn-mini layui-btn-danger del-btn"><i class="layui-icon"></i></button>' +
                '</div>' +
                '</td>' +
                '</tr>';
            return $html;
        }
        $("#paging").empty();
        $("#paging").append(generatePaging("{$appListCount}", "{$essentialInformation.page}", "", "{$essentialInformation.onePageData}"));

        function insertAppInfo(e) {
            var $html = listHtml(
                e.id,
                e.version,
                e._id,
                e.platform,
                e.upload_time,
                e.build_version,
                e.uorce_update,
                e.minimum_version_number,
                e.download_url,
                e.disable,
                e.disable_info,
                e.name
            );
            $("#app_list").prepend($html); //添加app列表
        }

        function locationHref($page) {

            requestData(
                "/{$useradmin}/App/AppSetting/AppList", {
                "page": $page,
                "uorce_update": $uorce_update,
                "disable": $disable,
                "onePageData": $onePageData,
            },
                (e) => {
                    if (e.code == 200) {
                        $("#paging").empty();
                        $("#app_list").empty();
                        $app_list = e.data.appList;
                        $html = "";
                        $.each($app_list, function (indexInArray, valueOfElement) {
                            $html += listHtml(valueOfElement.id, valueOfElement.platform, valueOfElement.uuid_id, valueOfElement.upload_time, valueOfElement.version, valueOfElement.build_version, valueOfElement.uorce_update, valueOfElement.minimum_version_number, valueOfElement.download_url, valueOfElement.disable, valueOfElement.disable_info, valueOfElement.user_name);
                        });
                        $("#app_list").append($html); //添加app列表
                        $("#paging").append(generatePaging(e.data.appListCount, e.data.essentialInformation.page, "", e.data.essentialInformation.onePageData)); //添加分页

                    } else {
                        layer.open({
                            type: 0,
                            skin: 'layui-layer-demo', //样式类名
                            title: "发生错误 错误代码" + e.code,
                            closeBtn: 0, //不显示关闭按钮
                            anim: 2,
                            maxWidth: '7%',
                            maxHeight: '70%',
                            shadeClose: false, //开启遮罩关闭
                            content: '<div style="max-width:100%">' +
                                '<li style="text-align:center;" class="layer-area">' +
                                '<div style="text-align:center;">' +
                                '<img  draggable="false" style="max-Width:70%;max-height:60%;" src="https://i0.hdslb.com/bfs/album/89f61ba7b2456dfd5af4bd92b485553274f73ad4.png">' +
                                '<div style="text-align:center;">' +
                                '<font>' + e.message + '</font>' +
                                '<font> 建议处理方法<p style="color:red">' + e.detail + '</p></font>' +
                                '</div>' +
                                '</div>' +
                                '</li>' +
                                '</div>',
                            btn: ['确认',] //可以无限个按钮
                            ,
                            btn1: function (index, layero) {
                                window.location.reload();
                            }
                        });
                    }
                    layer.close(loginTips);
                }
            );
        }

        layui.use(['form', 'jquery', 'layer', 'dialog'], function () {
            var $ = layui.jquery;
            var dialog = layui.dialog;

            //修改状态
            $('#app_list').on('click', '.button-app-isdisable', function () {
                var That = $(this);
                var status = That.attr('data-status');
                var id = That.parent().parent().attr('data-id');
                var uuid_id = That.parent().parent().attr('data-uuid_id');
                var version = That.parent().parent().attr('data-version');

                requestData(
                    "/{$useradmin}/App/AppSetting/SetIsDisable", {
                    "app_id": id,
                    "version": version,
                    "uuid_id": uuid_id,
                },
                    (e) => {
                        if (e.code == 200) {
                            if (e.data.disable) {
                                That.removeClass('layui-btn-normal').addClass('layui-btn-danger').html('禁用').attr('data-status', e.data.disable);
                            } else {
                                That.removeClass('layui-btn-danger').addClass('layui-btn-normal').html('正常').attr('data-status', e.data.disable);
                            }
                        } else {
                            layer.open({
                                type: 0,
                                skin: 'layui-layer-demo', //样式类名
                                title: "发生错误 错误代码" + e.code,
                                closeBtn: 0, //不显示关闭按钮
                                anim: 2,
                                maxWidth: '7%',
                                maxHeight: '70%',
                                shadeClose: false, //开启遮罩关闭
                                content: '<div style="max-width:100%">' +
                                    '<li style="text-align:center;" class="layer-area">' +
                                    '<div style="text-align:center;">' +
                                    '<img  draggable="false" style="max-Width:70%;max-height:60%;" src="https://i0.hdslb.com/bfs/album/89f61ba7b2456dfd5af4bd92b485553274f73ad4.png">' +
                                    '<div style="text-align:center;">' +
                                    '<font>' + e.message + '</font>' +
                                    '<font> 建议处理方法<p style="color:red">' + e.detail + '</p></font>' +
                                    '</div>' +
                                    '</div>' +
                                    '</li>' +
                                    '</div>',
                                btn: ['确认',] //可以无限个按钮
                                ,
                                btn1: function (index, layero) {
                                    window.location.reload();
                                }
                            });
                        }
                        layer.close(loginTips);
                    }
                );

            })

            //是否强制更新
            $('#app_list').on('click', '.button-app-is_uorce_update', function () {
                var That = $(this);
                var status = That.attr('data-status');
                var id = That.parent().parent().attr('data-id');
                var uuid_id = That.parent().parent().attr('data-uuid_id');
                var version = That.parent().parent().attr('data-version');
                var update_user_id = That.parent().parent().attr('data-update_user_id');

                requestData(
                    "/{$useradmin}/App/AppSetting/SetIsUorceUpdate", {
                    "app_id": id,
                    "version": version,
                    "uuid_id": uuid_id,
                },
                    (e) => {
                        if (e.code == 200) {
                            if (e.data.uorce_update) {
                                That.removeClass('layui-btn-danger').addClass('layui-btn-danger').html('是').attr('data-status', e.data.uorce_update);
                            } else {
                                That.removeClass('layui-btn-danger').addClass('layui-btn-normal').html('否').attr('data-status', e.data.uorce_update);
                            }
                        } else {
                            layer.open({
                                type: 0,
                                skin: 'layui-layer-demo', //样式类名
                                title: "发生错误 错误代码" + e.code,
                                closeBtn: 0, //不显示关闭按钮
                                anim: 2,
                                maxWidth: '7%',
                                maxHeight: '70%',
                                shadeClose: false, //开启遮罩关闭
                                content: '<div style="max-width:100%">' +
                                    '<li style="text-align:center;" class="layer-area">' +
                                    '<div style="text-align:center;">' +
                                    '<img  draggable="false" style="max-Width:70%;max-height:60%;" src="https://i0.hdslb.com/bfs/album/89f61ba7b2456dfd5af4bd92b485553274f73ad4.png">' +
                                    '<div style="text-align:center;">' +
                                    '<font>' + e.message + '</font>' +
                                    '<font> 建议处理方法<p style="color:red">' + e.detail + '</p></font>' +
                                    '</div>' +
                                    '</div>' +
                                    '</li>' +
                                    '</div>',
                                btn: ['确认',] //可以无限个按钮
                                ,
                                btn1: function (index, layero) {
                                    window.location.reload();
                                }
                            });
                        }
                        layer.close(loginTips);
                    }
                );

            })
            $('#screen-where').on('click', '.button-screen', function () {
                $uorce_update = ($("#uorce_update").val());
                $disable = ($("#disable").val());
                $onePageData = ($("#onePageData").val());
                requestData(
                    "/{$useradmin}/App/AppSetting/AppList", {
                    "page": 1,
                    "uorce_update": $uorce_update,
                    "disable": $disable,
                    "onePageData": $onePageData, //一页显示多少个
                },
                    (e) => {
                        if (e.code == 200) {
                            $("#paging").empty();
                            $("#app_list").empty();
                            $app_list = e.data.appList;
                            $html = "";
                            $.each($app_list, function (indexInArray, valueOfElement) {
                                $html += listHtml(valueOfElement.id, valueOfElement.platform, valueOfElement.uuid_id, valueOfElement.upload_time, valueOfElement.version, valueOfElement.build_version, valueOfElement.uorce_update, valueOfElement.minimum_version_number, valueOfElement.download_url, valueOfElement.disable, valueOfElement.disable_info, valueOfElement.user_name);
                            });
                            $("#app_list").append($html); //添加app列表
                            $("#paging").append(generatePaging(e.data.appListCount, e.data.essentialInformation.page, "", e.data.essentialInformation.onePageData)); //添加分页

                        } else {
                            layer.open({
                                type: 0,
                                skin: 'layui-layer-demo', //样式类名
                                title: "发生错误 错误代码" + e.code,
                                closeBtn: 0, //不显示关闭按钮
                                anim: 2,
                                maxWidth: '7%',
                                maxHeight: '70%',
                                shadeClose: false, //开启遮罩关闭
                                content: '<div style="max-width:100%">' +
                                    '<li style="text-align:center;" class="layer-area">' +
                                    '<div style="text-align:center;">' +
                                    '<img  draggable="false" style="max-Width:70%;max-height:60%;" src="https://i0.hdslb.com/bfs/album/89f61ba7b2456dfd5af4bd92b485553274f73ad4.png">' +
                                    '<div style="text-align:center;">' +
                                    '<font>' + e.message + '</font>' +
                                    '<font> 建议处理方法<p style="color:red">' + e.detail + '</p></font>' +
                                    '</div>' +
                                    '</div>' +
                                    '</li>' +
                                    '</div>',
                                btn: ['确认',] //可以无限个按钮
                                ,
                                btn1: function (index, layero) {
                                    window.location.reload();
                                }
                            });
                        }
                        layer.close(loginTips);
                    }
                );

            })
            //删除按钮
            $('#app_list').on('click', '.del-btn', function () {
                var That = $(this);
                var status = That.attr('data-status');
                var id = That.parent().parent().parent().attr('data-id');
                var uuid_id = That.parent().parent().parent().attr('data-uuid_id');
                var version = That.parent().parent().parent().attr('data-version');
                console.log(id);
                console.log(uuid_id);
                console.log(version);
                dialog.confirm({
                    message: '您确定要进行删除吗？',
                    success: function () {
                        requestData(
                            "/{$useradmin}/App/AppSetting/DeleteApp", {
                            "app_id": id,
                            "version": version,
                            "uuid_id": uuid_id,
                        },
                            (e) => {
                                if (e.code == 200) {
                                    That.closest('tr').remove();
                                } else {
                                    layer.open({
                                        type: 0,
                                        skin: 'layui-layer-demo', //样式类名
                                        title: "发生错误 错误代码" + e.code,
                                        closeBtn: 0, //不显示关闭按钮
                                        anim: 2,
                                        maxWidth: '7%',
                                        maxHeight: '70%',
                                        shadeClose: false, //开启遮罩关闭
                                        content: '<div style="max-width:100%">' +
                                            '<li style="text-align:center;" class="layer-area">' +
                                            '<div style="text-align:center;">' +
                                            '<img  draggable="false" style="max-Width:70%;max-height:60%;" src="https://i0.hdslb.com/bfs/album/89f61ba7b2456dfd5af4bd92b485553274f73ad4.png">' +
                                            '<div style="text-align:center;">' +
                                            '<font>' + e.message + '</font>' +
                                            '<font> 建议处理方法<p style="color:red">' + e.detail + '</p></font>' +
                                            '</div>' +
                                            '</div>' +
                                            '</li>' +
                                            '</div>',
                                        btn: ['确认',] //可以无限个按钮
                                        ,
                                        btn1: function (index, layero) {
                                            window.location.reload();
                                        }
                                    });
                                }
                                layer.close(loginTips);
                            }
                        );
                        layer.msg('删除成功')
                    },
                    cancel: function () {
                        layer.msg('您已取消删除')
                    }
                })
                return false;
            })
        });
        var loginTips;
        var $uorce_update = 999999999999999;
        var $disable = 999999999999999;
        var $onePageData;


    </script>


</body>

</html>